package com.chiyoyo.rabbitmq.framework.service.impl;

import com.chiyoyo.rabbitmq.framework.annotation.RabbitMq;
import com.chiyoyo.rabbitmq.framework.service.AbstractMQService;
import org.springframework.amqp.core.*;
import org.springframework.stereotype.Service;

/**
 * @author chil
 * RabbitMq广播队列注册
 */
@Service("fanoutMQService")
public class FanoutMQService extends AbstractMQService {

    @Override
    protected AbstractExchange initExchange(String exchangeName, RabbitMq rabbitMq) {
        return new FanoutExchange(exchangeName);
    }

    @Override
    protected Binding initBinding(Queue queue, AbstractExchange exchange, String routingKey, RabbitMq rabbitMq) {
        //  重写父类方法，创建并返回一个绑定，将队列绑定到一个FanoutExchange类型的交换器上
        //  FanoutExchange不需要routingKey，这里传入的routingKey不会被使用
        return BindingBuilder.bind(queue).to((FanoutExchange) exchange);
    }
}
